package com.epam.facebook_client;

import android.app.Activity;
import android.content.Intent;
import android.content.SharedPreferences.Editor;
import android.os.Bundle;
import android.util.Log;

import com.facebook.Session;

public class StartActivity extends Activity {

	public static final String TOKEN = "token";
	public static final String FILE_NAME = "preferences";
	
	private static final String EMPTY = "";

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		Session session = Session.getActiveSession();
		String token = null;
		if (session != null && session.isOpened()) {
			token = session.getAccessToken();
			Log.i("SESSION Permissions", session.getPermissions().toString());
		}
		if (token != null && !token.equals(EMPTY)) {
			Editor edit = getSharedPreferences(FILE_NAME, 0).edit();
			edit.putString(TOKEN, token);
			edit.commit();
			startActivity(new Intent(this, HomeActivity.class));
		} else {
			startActivity(new Intent(this, LoginActivity.class));
		}
		finish();
	}
}





